package com.labor_management_system.Service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.labor_management_system.Entity.ProjectList;
import com.labor_management_system.Service.ProjectListService;
import com.labor_management_system.Mapper.ProjectListMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author deathwing475
* @description 针对表【project_list】的数据库操作Service实现
* @createDate 2024-02-27 09:54:57
*/
@Service
public class ProjectListServiceImpl extends ServiceImpl<ProjectListMapper, ProjectList>
    implements ProjectListService {
    //项目清单



    @Override
    public Boolean inserBatchList(List<ProjectList> projectLists) {

        int row =0;

        for (int i=0;i<projectLists.size();i++){
            baseMapper.insert(projectLists.get(i));
            row++;
        }

        if(row==projectLists.size()){
            return true;
        }

        return false;
    }

    @Override
    public List<ProjectList> selectProjectListById(String projectId) {
        QueryWrapper<ProjectList> queryWrapper = new QueryWrapper<>();

        queryWrapper.eq("project_id",projectId);

        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public boolean updateBatchList(List<ProjectList> projectLists,String projectId) {
        int update =0;

        for (int i=0;i<projectLists.size();i++){
            //判断是新增还是更新
            QueryWrapper<ProjectList> queryWrapper = new QueryWrapper<>();

            queryWrapper.eq("project_list_id",projectLists.get(i).getProjectListId());

            update = baseMapper.update(projectLists.get(i),queryWrapper);

            if(update ==0){
                //判断更新成功否，如果新增的没有id，换成新增
                projectLists.get(i).setProjectId(projectId);
                baseMapper.insert(projectLists.get(i));
            }

            update =0;
        }

        return true;
    }
    @Override
    public void deleteprojectlist(String projectListId) {
        baseMapper.deleteById(projectListId);
    }
}




